﻿using LightOMator.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightOMator.ViewModel
{
    public class SettingsViewModel : BusyViewModel
    {

        private bool _isStartPageSingle;
        public bool IsStartPageSingle
        {
            get { return _isStartPageSingle; }
            set
            {
                if (value != _isStartPageSingle)
                {
                    _isStartPageSingle = value;
                    RaisePropertyChanged();
                    Settings.StartPage = Settings.SettingsStartPage.single;
                }
            }
        }

        private bool _isStartPageMultiple;
        public bool IsStartPageMultiple
        {
            get { return _isStartPageMultiple; }
            set
            {
                if (value != _isStartPageMultiple)
                {
                    _isStartPageMultiple = value;
                    RaisePropertyChanged();
                    Settings.StartPage = Settings.SettingsStartPage.multiple;
                }
            }
        }

        private bool _isStartPageSaved;
        public bool IsStartPageSaved
        {
            get { return _isStartPageSaved; }
            set
            {
                if (value != _isStartPageSaved)
                {
                    _isStartPageSaved = value;
                    RaisePropertyChanged();
                    Settings.StartPage = Settings.SettingsStartPage.saved;
                }
            }
        }

        private int _fadeInStartRange;
        public int FadeInStartRange
        {
            get { return _fadeInStartRange; }
            set
            {
                if (value != _fadeInStartRange)
                {
                    _fadeInStartRange = value;
                    RaisePropertyChanged();
                    Settings.FadeInStartRangeMs = value;
                }
            }
        }

        private int _fadeInEndRange;
        public int FadeInEndRange
        {
            get { return _fadeInEndRange; }
            set
            {
                if (value != _fadeInEndRange)
                {
                    if (value < 1000)
                    {
                        value = 1000;
                    }
                    _fadeInEndRange = value;
                    RaisePropertyChanged();
                    Settings.FadeInEndRangeMs = value;
                }
            }
        }

        private int _keepOnStartRange;
        public int KeepOnStartRange
        {
            get { return _keepOnStartRange; }
            set
            {
                if (value != _keepOnStartRange)
                {
                    _keepOnStartRange = value;
                    RaisePropertyChanged();
                    Settings.KeepOnStartRangeMs = value;
                }
            }
        }

        private int _keepOnEndRange;
        public int KeepOnEndRange
        {
            get { return _keepOnEndRange; }
            set
            {
                if (value != _keepOnEndRange)
                {
                    if (value < 1000)
                    {
                        value = 1000;
                    }
                    _keepOnEndRange = value;
                    RaisePropertyChanged();
                    Settings.KeepOnEndRangeMs = value;
                }
            }
        }

        public Settings Settings { get; set; }

        public SettingsViewModel()
        {
            Settings settings = Settings.Instance;
            if (settings.StartPage == Settings.SettingsStartPage.single)
            {
                _isStartPageSingle = true;
                _isStartPageMultiple = false;
                _isStartPageSaved = false;
            }
            else if (settings.StartPage == Settings.SettingsStartPage.multiple)
            {
                _isStartPageSingle = false;
                _isStartPageMultiple = true;
                _isStartPageSaved = false;
            }
            else
            {
                _isStartPageSingle = false;
                _isStartPageMultiple = false;
                _isStartPageSaved = true;
            }
            _fadeInStartRange = settings.FadeInStartRangeMs;
            _fadeInEndRange = settings.FadeInEndRangeMs;
            _keepOnStartRange = settings.KeepOnStartRangeMs;
            _keepOnEndRange = settings.KeepOnEndRangeMs;
            Settings = settings;
        }


    }
}
